# -*- coding: utf-8 -*-
"""
Created on Wed Apr 22 14:39:04 2020

@author: yu
"""

import random
from tkinter import _flatten
class od(): 
    def __init__(self,seedNum,totVeh):
        
        self.seedNum=seedNum
        self.totVeh=totVeh
    
    def getO(self):
    # 伪随机，能选中1或2个数字
        randomO=self.totVeh/3
        loopT=0
        randomT=self.totVeh/3
        startL=[]
        childPool=[]
        for i in range(1,self.totVeh+1):
            childPool.append(str(i))
        random.seed(self.seedNum)
        random.shuffle(childPool)
        while True:
            
            loopT+=1
            if randomO!=0  and randomT!=0:
                carNum=random.sample([1,2],1)
            elif randomO==0 and randomT!=0:
                carNum=[2]
            elif randomO!=0 and randomT==0:
                carNum=[1]
            else:
                break
            if carNum==[1]:
                randomO-=1
            else:
                randomT-=1
            #print('loopT',loopT,'randomNum',carNum)
            ranRow=[]
            #print('childPool',childPool)
            for _ in range(carNum[0]):
                ranRow.append(childPool[0])
                childPool.remove(childPool[0])
            #print('childPool after remove',childPool)
            while len(ranRow)<3:
                ranRow.append('0')
            random.shuffle(ranRow)
            #print('ranRow',ranRow)
            startL.append(ranRow)
            
            startL=list(_flatten(startL))
        return startL
   
    
    

#print('startL',od(1,6).getO())
#,'endL',od().getD()







